/*eslint-disable*/
import * as dd from "dingtalk-jsapi";
interface UtilsProps {
  hasOwnProperty: (target: any, key: string) => boolean;
  getLocalStorage: (storageString?: string) => string | null | undefined;
  setLocalStorage: (setKey: string, setValue: any) => void;
  clearLocalStorage: () => void;
  removeLocalStorageKey: (removeItemKey: string) => void;
  initNavTitle: (title: string) => void;
}
export function debounce(fun: any, delay: number) {
  let timer: any = null;
  return (...args: any) => {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      fun.apply(fun, args);
    }, delay);
  };
}
export const initNavTitle: UtilsProps["initNavTitle"] = (title) => {
  if (dd.env.platform == "notInDingTalk") {
    console.warn("不在钉钉容器内");
    return;
  }

  dd.ready(function() {
    dd.biz.navigation.setTitle({
      title, //控制标题文本，空字符串表示显示默认文本
    });
  });
};
export const hasOwnProperty: UtilsProps["hasOwnProperty"] = (target, key) => {
  if (!Object.keys(target).length) {
    return false;
  }
  return Object.prototype.hasOwnProperty.call(target, key);
};

export const getLocalStorage: UtilsProps["getLocalStorage"] = (
  storageString?: string
) => {
  return storageString && localStorage.getItem(storageString);
};

export const setLocalStorage: UtilsProps["setLocalStorage"] = (
  setKey: string,
  setValue: any
) => {
  localStorage.setItem(setKey, setValue);
};

export const clearLocalStorage: UtilsProps["clearLocalStorage"] = () => {
  localStorage.clear();
};

export function removeToken(): void {
  localStorage.clear();
  sessionStorage.clear();
}

export const GAO_DE_KEY = "b6ff6862fba505d4b6210c854552efea";
export const KK_URL = "http://115.239.175.246:5004";
export const appName = "富阳财政服务E平台";
export const appId = "5";
export let BASE_URL = "";
export let CROP_ID = "";

const NODE_ENV = process.env.NODE_ENV;
if (NODE_ENV === "development") {
  CROP_ID = "ding2cad6344a207268935c2f4657eb6378f"; //本地
  // BASE_URL = "http://10.10.10.143:8084"; //fu
  BASE_URL = "http://115.239.175.246:5101/czfwpt"; //ww
} else {
         //? 柯桥
         
  /* CROP_ID = "ding9327ba037b5d8a9b4ac5d6980864d335"; 
  BASE_URL = "https://czfwpt.fuyang.gov.cn/czfwptStage"; */ 
         //? 柯桥

  CROP_ID = "dinga5f9b5185f38329135c2f4657eb6378f"; 
  BASE_URL = "https://czept.kq.gov.cn/kqczfwpt";

        //? 本地
  /* CROP_ID = "ding2cad6344a207268935c2f4657eb6378f"; //本地
  BASE_URL = "http://10.10.10.165:8084/";  */
       }
// ----------------------------- 动态
/* const a = "http://" + window.location.host;

const urlArr = a.split(":");
urlArr.pop();
export const BASE_URL =
  urlArr.toString().replace(",", ":") + ":8083/czfwptStage";
 */
// -----------------------------

export const removeLocalStorageKey: UtilsProps["removeLocalStorageKey"] = (
  removeItemKey: string
) => {
  localStorage.removeItem(removeItemKey);
};

export const StringProp = (target: any) => {
  return Object.prototype.toString.call(target) === "[object String]";
};

export const FunctionProp = (target: any) => {
  return Object.prototype.toString.call(target) === "[object Function]";
};
